This program examines blocks that only partially intersect with community districts.

General information

The starting point for downloading most Census shapefiles is here. You can find more about the census redistricting files here.

It helps to know the FIPS (Federal Information Processing System) codes for Kansas (20) and Missouri (29).

The important counties for this program are

Cass County, MO (29037) Clay County, MO (29047) Jackson County, MO (29095) Johnson County, KS (20091) Leavenworth County, KS (20103) Platte County, MO (29165) Wyandotte County, KS (20209)

Load relevant files

library(sf)
## Linking to GEOS 3.9.0, GDAL 3.2.1, PROJ 7.2.1
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.4     v dplyr   1.0.7
## v tidyr   1.1.3     v stringr 1.4.0
## v readr   2.0.1     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
path_name <- "../data/"
load(paste0(path_name, "weights", ".RData"))
glimpse(b0)
## Rows: 15,748
## Columns: 7
## $ bl_id    <chr> "290950023002014", "290950063002017", "290950022003001", "290~
## $ bl_name  <chr> "Block 2014", "Block 2017", "Block 3001", "Block 3004", "Bloc~
## $ bl_area  <dbl> 14983.197, 9597.627, 18151.722, 18380.541, 17691.230, 17458.2~
## $ cd_id    <dbl> 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 1~
## $ cd_name  <chr> "East Side", "East Side", "East Side", "East Side", "East Sid~
## $ cd_area  <dbl> 281713850, 281713850, 281713850, 281713850, 281713850, 281713~
## $ geometry <GEOMETRY [°]> POLYGON ((-94.5324 39.0887,..., POLYGON ((-94.56127 ~
glimpse(b1)
## Rows: 41,220
## Columns: 13
## $ bl_id         <chr> "290950023002014", "290950063002017", "290950022003001",~
## $ cd_id         <dbl> 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 1~
## $ prop_in       <dbl> 1.000000000, 1.000000000, 1.000000000, 1.000000000, 1.00~
## $ st_id         <chr> "29", "29", "29", "29", "29", "29", "29", "29", "29", "2~
## $ co_id         <chr> "29095", "29095", "29095", "29095", "29095", "29095", "2~
## $ tr_id         <chr> "29095002300", "29095006300", "29095002200", "2909500220~
## $ bg_id         <chr> "290950023002", "290950063002", "290950022003", "2909500~
## $ people        <dbl> 62, 0, 22, 26, 42, 49, 43, 0, 12, 20, 5, 56, 58, 48, 47,~
## $ housing_units <dbl> 18, 0, 9, 18, 22, 22, 14, 0, 1, 10, 4, 12, 19, 24, 28, 4~
## $ land_area     <chr> "14996", "9606", "18167", "18396", "17706", "17473", "32~
## $ water_area    <chr> "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "~
## $ block_lat     <chr> "+39.0894021", "+39.0439974", "+39.0932160", "+39.093298~
## $ block_lon     <chr> "-094.5318307", "-094.5610343", "-094.5240738", "-094.52~
glimpse(b2)
## Rows: 2,314
## Columns: 6
## Groups: bg_id [1,684]
## $ bg_id            <chr> "200910500001", "200910500001", "200910500002", "2009~
## $ cd_id            <dbl> 209, NA, 209, NA, 209, NA, NA, NA, NA, 209, 211, NA, ~
## $ people_in        <dbl> 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0,~
## $ people           <dbl> 744, 744, 695, 695, 751, 751, 817, 680, 1378, 1313, 1~
## $ housing_units_in <dbl> 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0,~
## $ housing_units    <dbl> 341, 341, 311, 311, 377, 377, 371, 284, 612, 648, 648~
load(paste0(path_name, "bl", ".RData"))
glimpse(bl)
## Rows: 39,903
## Columns: 4
## $ bl_id    <chr> "200910518012010", "200910514003006", "200910515002005", "200~
## $ bl_name  <chr> "Block 2010", "Block 3006", "Block 2005", "Block 1009", "Bloc~
## $ bl_area  <dbl> 38500.823, 51711.677, 104537.047, 73933.762, 95854.528, 19934~
## $ geometry <POLYGON [°]> POLYGON ((-94.64213 38.9774..., POLYGON ((-94.63966 3~
load(paste0(path_name, "cd", ".RData"))
glimpse(cd)
## Rows: 59
## Columns: 4
## $ cd_id    <dbl> 106, 108, 113, 102, 129, 116, 114, 101, 105, 103, 107, 109, 1~
## $ cd_name  <chr> "East Side", "Old Northeast", "Greater Downtown", "Blue Valle~
## $ cd_area  <dbl> 281713850, 118237219, 181920811, 216842678, 412671242, 264282~
## $ geometry <POLYGON [°]> POLYGON ((-94.52337 39.0941..., POLYGON ((-94.50777 3~

List blocks that are split between communities

b1                                     %>%
  mutate(dev=abs(prop_in-0.5))         %>%
  arrange(dev)                          -> dev
dev                                    %>%
  print(n=20)
## # A tibble: 41,220 x 14
##    bl_id   cd_id prop_in st_id co_id tr_id  bg_id people housing_units land_area
##    <chr>   <dbl>   <dbl> <chr> <chr> <chr>  <chr>  <dbl>         <dbl> <chr>    
##  1 202090~   216   0.502 20    20209 20209~ 2020~      0             0 0        
##  2 202090~   214   0.498 20    20209 20209~ 2020~      0             0 0        
##  3 290470~   122   0.493 29    29047 29047~ 2904~      0             1 53765    
##  4 290950~   132   0.492 29    29095 29095~ 2909~      0             0 14600    
##  5 290950~   127   0.508 29    29095 29095~ 2909~      0             0 14600    
##  6 290950~   102   0.487 29    29095 29095~ 2909~      0             0 0        
##  7 290950~   101   0.513 29    29095 29095~ 2909~      0             0 0        
##  8 202090~   203   0.513 20    20209 20209~ 2020~      0             0 1718     
##  9 202090~   210   0.515 20    20209 20209~ 2020~      0             0 12583    
## 10 202090~   209   0.485 20    20209 20209~ 2020~      0             0 12583    
## 11 291650~   124   0.518 29    29165 29165~ 2916~     24             1 2604     
## 12 291650~   123   0.482 29    29165 29165~ 2916~     24             1 2604     
## 13 202090~   219   0.482 20    20209 20209~ 2020~      0             0 1718     
## 14 202099~   208   0.522 20    20209 20209~ 2020~      0             0 0        
## 15 202099~   202   0.478 20    20209 20209~ 2020~      0             0 0        
## 16 290950~   101   0.477 29    29095 29095~ 2909~     20             2 2731     
## 17 291650~   121   0.476 29    29165 29165~ 2916~    141            65 306801   
## 18 291650~   124   0.524 29    29165 29165~ 2916~    141            65 306801   
## 19 202090~   211   0.524 20    20209 20209~ 2020~      0             0 4044     
## 20 202090~   210   0.476 20    20209 20209~ 2020~      0             0 4044     
## # ... with 41,200 more rows, and 4 more variables: water_area <chr>,
## #   block_lat <chr>, block_lon <chr>, dev <dbl>

Map split blocks

for (i in 1:500) {
  cd                                   %>%
    filter(cd_id==dev$cd_id[i])         -> cd_i
  bl                                   %>%
    filter(bl_id==dev$bl_id[i])         -> bl_i
  ti <- paste0(
    cd_i$cd_name, ", ",
    bl_i$bl_name, ", ",
    round(100*dev$prop_in[i]), "%")
  cd_i                                 %>%
    ggplot(aes())                       +
      geom_sf(
        fill="white", 
        color="darkgreen")              +
      ggtitle(ti)                       +
      geom_sf(
        data=bl_i,
        aes(), 
        fill=NA,
        color="darkred")                -> map_i
  plot(map_i)
  b0                                   %>%
    filter(cd_id==dev$cd_id[i])        %>%
    filter(bl_id==dev$bl_id[i])         -> b0_i
  bl_i                                 %>%
    ggplot(aes())                       +
      geom_sf(
        fill=NA,
        color="darkgreen")              +
      ggtitle("Closeup view")           +
      geom_sf(
        data=b0_i,
        aes(), 
        fill="white",
        color="darkred")                -> closeup_i
  plot(closeup_i)
}